<template>
    <div>
        <main>
            <form class="form" @submit="submit">
                <div class="form__cover"></div>
                <div class="form__loader">
                    <div class="spinner active">
                        <svg class="spinner__circular" viewBox="25 25 50 50">
                            <circle
                                class="spinner__path"
                                cx="50"
                                cy="50"
                                r="20"
                                fill="none"
                                stroke-width="4"
                                stroke-miterlimit="10"
                            />
                        </svg>
                    </div>
                </div>
                <div class="form__content">
                    <h1 class="form__content_h1">Login</h1>
                    <div class="styled-input">
                        <input type="text" class="styled-input__input" name="username" v-model="userForm.username" />
                        <div class="styled-input__placeholder">
                            <span class="styled-input__placeholder-text">Username</span>
                        </div>
                        <div class="styled-input__circle"></div>
                    </div>
                    <div class="styled-input">
                        <input type="password" class="styled-input__input" name="password" v-model="userForm.password" @keydown="typing($event)" />
                        <div class="styled-input__placeholder">
                            <span class="styled-input__placeholder-text">Password</span>
                        </div>
                        <div class="styled-input__circle"></div>
                    </div>
                    <button type="button" class="styled-button" @click="submit">
                        <span class="styled-button__real-text-holder">
                            <span class="styled-button__real-text">Submit</span>
                            <span class="styled-button__moving-block face">
                                <span class="styled-button__text-holder">
                                    <span class="styled-button__text">Submit</span>
                                </span>
                            </span>
                            <span class="styled-button__moving-block back">
                                <span class="styled-button__text-holder">
                                    <span class="styled-button__text">Submit</span>
                                </span>
                            </span>
                        </span>
                    </button>
                </div>
            </form>
        </main>
    </div>
</template>

<script>
import md5 from 'js-md5'
export default {
    data() {
        return {
            userForm: {
                password: '',
                username: ''
            },
        }
    },
    created() {
        document.body.classList.add('login')
    },
    mounted() {
        var placeholders = document.querySelectorAll('.styled-input__placeholder-text'),
            inputs = document.querySelectorAll('.styled-input__input');

        placeholders.forEach(function (el, i) {
            var value = el.innerText,
                html = '';
            for (var _iterator = value, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator](); ;) {
                var _ref;

                if (_isArray) {
                    if (_i >= _iterator.length) break;
                    _ref = _iterator[_i++];
                } else {
                    _i = _iterator.next();
                    if (_i.done) break;
                    _ref = _i.value;
                }

                var w = _ref;

                if (!value) value = '&nbsp;';
                html += '<span class="letter">' + w + '</span>';
            }
            el.innerHTML = html;
        });

        inputs.forEach(function (el) {
            var parent = el.parentNode;
            el.addEventListener('focus', function () {
                parent.classList.add('filled');
                placeholderAnimationIn(parent, true);
            }, false);
            el.addEventListener('blur', function () {
                if (el.value.length) return;
                parent.classList.remove('filled');
                placeholderAnimationIn(parent, false);
            }, false);
        });

        function placeholderAnimationIn(parent, action) {
            var act = action ? 'add' : 'remove';
            var letters = parent.querySelectorAll('.letter');
            letters = [].slice.call(letters, 0);
            if (!action) letters = letters.reverse();
            letters.forEach(function (el, i) {
                setTimeout(function () {
                    var contains = parent.classList.contains('filled');
                    if (action && !contains || !action && contains) return;
                    el.classList[act]('active');
                }, 50 * i);
            });
        }

        setTimeout(function () {
            document.body.classList.add('on-start');
        }, 100);

        setTimeout(function () {
            document.body.classList.add('document-loaded');
        }, 1500);

    },
    methods: {
        submit() { // 确认登陆
            if (!this.userForm.username || !this.userForm.password) {
                this.$message({
                    type: 'warning',
                    message: "用户名或密码不能为空"
                });
                return false;
            }
            else {
                this.userForm.password = md5(this.userForm.password)
                this.$axios({
                    url: "/admin/login",
                    method: "post",
                    data: this.userForm
                }).then(res => {
                    if (res.data.code == 1) {
                        this.$message({
                            type: 'success',
                            message: res.data.msg
                        });
                        this.$router.push({ name: 'admhome' })
                    } else {
                        this.$message({
                            type: 'danger',
                            message: res.data.msg
                        });
                        return false;
                    }
                })
            }
        },
        typing(e) { // 判断是否为回车键
            if (e.keyCode == 13) {
                this.submit();
            }
        }
    },
    destroyed() {
        document.body.classList = []
    }
}
</script>

<style>
/* @import url("https://fonts.googleapis.com/css?family=Roboto"); */
body.login {
    all: initial;
    font-family: "Roboto", sans-serif;
    letter-spacing: 0.02em;
}
* {
    box-sizing: border-box;
}
main {
    font-family: "Roboto", sans-serif;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex !important;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    background: #3f2766;
    /* ************* */
    background: #222;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 7px,
        rgba(0, 0, 0, 0.8) 9px,
        rgba(0, 0, 0, 0.8) 13px,
        transparent 13px
    );
}
.form {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    position: relative;
    width: 400px;
    height: 400px;
    -ms-flex-negative: 0;
    flex-shrink: 0;
    padding: 20px;
    border-radius: 5px;
}
.form__loader {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    z-index: -4;
    -webkit-transition: all 0.5s ease;
    transition: all 0.5s ease;
}
.form__content {
    text-align: center;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    position: relative;
    opacity: 0;
    -webkit-transform: translateY(10px);
    transform: translateY(10px);
    -webkit-transition: all 0.5s ease 0.7s;
    transition: all 0.5s ease 0.7s;
}
.form__cover {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    z-index: -4;
    border-radius: 7px;
    overflow: hidden;
    -webkit-transition: all 0.3s ease 0.8s;
    transition: all 0.3s ease 0.8s;
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}
.form__cover:after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    /* background: #4d317a; */
    z-index: -4;
    border-radius: 50%;
    -webkit-transition: all 1.5s ease 0.3s;
    transition: all 1.5s ease 0.3s;
    -webkit-transform: scale(0);
    transform: scale(0);
}
.form__cover:before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    /* background: white; */
    z-index: -5;
    border-radius: 50%;
    -webkit-transition: all 0.5s ease;
    transition: all 0.5s ease;
    -webkit-transform: scale(0);
    transform: scale(0);
}
body.on-start .form__cover:before {
    -webkit-transform: scale(0.15);
    transform: scale(0.15);
}
body.document-loaded .form__loader {
    -webkit-transform: scale(0);
    transform: scale(0);
    opacity: 0;
    visibility: hidden;
}
body.document-loaded .form__content {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
}
body.document-loaded .form__cover {
    /* box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); */
}
body.document-loaded .form__cover:after {
    -webkit-transform: scale(2);
    transform: scale(2);
}
body.document-loaded .form__cover:before {
    -webkit-transition: opacity 0.3s ease 0.8s, -webkit-transform 2s ease;
    transition: opacity 0.3s ease 0.8s, -webkit-transform 2s ease;
    transition: transform 2s ease, opacity 0.3s ease 0.8s;
    transition: transform 2s ease, opacity 0.3s ease 0.8s,
        -webkit-transform 2s ease;
    -webkit-transform: scale(2);
    transform: scale(2);
    opacity: 0;
}
h1.form__content_h1 {
    font-size: 40px;
    margin: 15px 0 20px 0;
    letter-spacing: 0.05em;
    color: #714cab;
    font-weight: 700;
    /* ********************** */
    text-shadow: 0 0 5px #ffa500, 0 0 15px #ffa500, 0 0 20px #ffa500,
        0 0 40px #ffa500, 0 0 60px #ff0000, 0 0 10px #ff8d00, 0 0 98px #ff0000;
    color: #fff6a9;
    animation: blink 5s infinite;
}
.styled-button {
    -webkit-appearance: none;
    -webkit-user-select: none;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
    padding: 20px;
    outline: none;
    background: none;
    position: relative;
    /* color: #492e72; */
    color: #8b5dd1;
    border-radius: 3px;
    margin-bottom: 25px;
    border: none;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.1em;
    /* background: #714cac; */
    /* background-color: rgba(255, 255, 255, 0.2); */
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    overflow: hidden;
}
.styled-button__real-text-holder {
    position: relative;
}
.styled-button__real-text {
    color: transparent;
    display: inline-block;
}
.styled-button__text-holder {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
}
.styled-button__moving-block {
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
}
.styled-button__moving-block.back {
    color: white;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
}
.styled-button__moving-block.back .styled-button__text-holder {
    -webkit-transform: translateX(100%);
    transform: translateX(100%);
}
.styled-button:hover,
.styled-button:active {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    /* background: #7a51bb; */
    background-color: rgba(255, 255, 255, 0.2);
}
.styled-button:hover .face,
.styled-button:active .face {
    -webkit-transform: translateX(100%);
    transform: translateX(100%);
}
.styled-button:hover .face .styled-button__text-holder,
.styled-button:active .face .styled-button__text-holder {
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
}
.styled-button:hover .back,
.styled-button:active .back {
    -webkit-transform: translateX(0);
    transform: translateX(0);
}
.styled-button:hover .back .styled-button__text-holder,
.styled-button:active .back .styled-button__text-holder {
    -webkit-transform: translateX(0);
    transform: translateX(0);
}
.styled-button:active {
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
.styled-input {
    width: 100%;
    position: relative;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
}
.styled-input__circle {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: -2;
    overflow: hidden;
    border-radius: 3px;
}
.styled-input__circle:after {
    content: "";
    position: absolute;
    left: 16.5px;
    top: 19px;
    height: 14px;
    width: 14px;
    z-index: -2;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0);
    -webkit-transition: opacity 1s ease, -webkit-transform 0.6s ease;
    transition: opacity 1s ease, -webkit-transform 0.6s ease;
    transition: transform 0.6s ease, opacity 1s ease;
    transition: transform 0.6s ease, opacity 1s ease,
        -webkit-transform 0.6s ease;
}
.styled-input__input {
    width: 100%;
    -webkit-appearance: none;
    font-size: 14px;
    outline: none;
    background: none;
    padding: 18px 15px;
    color: #ceafff;
    border: none;
    font-weight: 600;
    letter-spacing: 0.035em;
}
.styled-input__placeholder {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    z-index: -1;
    padding-left: 45px;
    color: white;
}
.styled-input__placeholder-text {
    -webkit-perspective: 500px;
    perspective: 500px;
    display: inline-block;
}
.styled-input__placeholder-text .letter {
    display: inline-block;
    vertical-align: middle;
    position: relative;
    -webkit-animation: letterAnimOut 0.25s ease forwards;
    animation: letterAnimOut 0.25s ease forwards;
    text-shadow: 0 0 5px;
}
.styled-input__placeholder-text .letter.active {
    -webkit-animation: letterAnimIn 0.25s ease forwards;
    animation: letterAnimIn 0.25s ease forwards;
}
.styled-input:hover {
    border-color: rgba(255, 255, 255, 0.4);
}
.styled-input.filled {
    border-color: rgba(255, 255, 255, 0.2);
}
.styled-input.filled .styled-input__circle:after {
    -webkit-transform: scale(37);
    transform: scale(37);
    opacity: 0;
}
@-webkit-keyframes letterAnimIn {
    0% {
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
    25% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        color: red;
    }
    45% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
        color: red;
    }
    55% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
    }
    56% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 0;
        color: #00ff6b;
    }
    76% {
        color: #00ff6b;
        opacity: 1;
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
    }
    100% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 1;
    }
}
@keyframes letterAnimIn {
    0% {
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
    25% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        color: red;
    }
    45% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
        color: red;
    }
    55% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
    }
    56% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 0;
        color: #00ff6b;
    }
    76% {
        color: #00ff6b;
        opacity: 1;
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
    }
    100% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 1;
    }
}
@-webkit-keyframes letterAnimOut {
    0% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 1;
    }
    25% {
        -webkit-transform: translate(-30px, -40px);
        transform: translate(-30px, -40px);
        opacity: 0;
    }
    45% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
    }
    55% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
        color: red;
    }
    56% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        color: red;
    }
    100% {
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
}
@keyframes letterAnimOut {
    0% {
        -webkit-transform: translate(-30px, -27px);
        transform: translate(-30px, -27px);
        opacity: 1;
    }
    25% {
        -webkit-transform: translate(-30px, -40px);
        transform: translate(-30px, -40px);
        opacity: 0;
    }
    45% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
    }
    55% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        opacity: 0;
        color: red;
    }
    56% {
        -webkit-transform: translate(0, 10px);
        transform: translate(0, 10px);
        color: red;
    }
    100% {
        -webkit-transform: translate(0, 0);
        transform: translate(0, 0);
    }
}
.spinner {
    position: relative;
    margin: auto;
    width: 50px;
    height: 50px;
    -webkit-transition: all 0.2s ease 0s;
    transition: all 0.2s ease 0s;
}
.spinner__circular {
    -webkit-animation: rotate 1.5s linear infinite;
    animation: rotate 1.5s linear infinite;
    -webkit-animation-play-state: paused;
    animation-play-state: paused;
    -webkit-transform-origin: center center;
    transform-origin: center center;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    margin: auto;
}
.spinner__path {
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
    -webkit-animation: dash 1.3s ease forwards 0.5s;
    animation: dash 1.3s ease forwards 0.5s;
    opacity: 0;
    stroke-linecap: round;
    stroke: #7b23ff;
    -webkit-animation-play-state: running;
    animation-play-state: running;
}
@-webkit-keyframes dash {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
        opacity: 0;
    }
    50% {
        stroke-dasharray: 40, 200;
        opacity: 1;
    }
    100% {
        stroke-dasharray: 125, 200;
        opacity: 1;
    }
}
@keyframes dash {
    0% {
        stroke-dasharray: 1, 200;
        stroke-dashoffset: 0;
        opacity: 0;
    }
    50% {
        stroke-dasharray: 40, 200;
        opacity: 1;
    }
    100% {
        stroke-dasharray: 125, 200;
        opacity: 1;
    }
}
@keyframes blink {
    20%,
    24%,
    55% {
        color: #111;
        text-shadow: none;
    }

    0%,
    19%,
    21%,
    23%,
    25%,
    54%,
    56%,
    100% {
        /*     color: #fccaff;
      text-shadow: 0 0 5px #f562ff, 0 0 15px #f562ff, 0 0 25px #f562ff,
        0 0 20px #f562ff, 0 0 30px #890092, 0 0 80px #890092, 0 0 80px #890092; */
        text-shadow: 0 0 5px #ffa500, 0 0 15px #ffa500, 0 0 20px #ffa500,
            0 0 40px #ffa500, 0 0 60px #ff0000, 0 0 10px #ff8d00,
            0 0 98px #ff0000;
        color: #fff6a9;
    }
}
</style>